//
//  StartListViewController.m
//  LiveStar
//
//  Created by SKT1 on 2016/12/1.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "StartListViewController.h"

@interface StartListViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property (nonatomic, strong)UITableView *tableView;
@end

@implementation StartListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setUpUI];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *login = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    login.backgroundColor = [UIColor redColor];
    [login setTitle:@"微信支付" forState:UIControlStateNormal];
    [login addTarget:self action:@selector(WXPay) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:login];
    
    UIButton *login1 = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
    login1.backgroundColor = [UIColor redColor];
    [login1 setTitle:@"照片选择" forState:UIControlStateNormal];
    [login1 addTarget:self action:@selector(photo) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:login];
    [self.view addSubview:login1];
    

    // Do any additional setup after loading the view.
}

#pragma mark --  照片选择
- (void)photo {
    UIImagePickerController *pickerVc = [[UIImagePickerController alloc] init];
    
    //设置照片可否编辑
    pickerVc.allowsEditing = YES;
    
    pickerVc.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    
    pickerVc.delegate = self;
    
    [self.navigationController presentViewController:pickerVc animated:YES completion:nil];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    
}
#pragma mark -- 微信支付
#pragma mark 微信支付方法
- (void)WXPay{
    
    //需要创建这个支付对象
    PayReq *req   = [[PayReq alloc] init];
    //由用户微信号和AppID组成的唯一标识，用于校验微信用户
    req.openID = @"";
    
    // 商家id，在注册的时候给的
    req.partnerId = @"";
    
    // 预支付订单这个是后台跟微信服务器交互后，微信服务器传给你们服务器的，你们服务器再传给你
    req.prepayId  = @"";
    
    // 根据财付通文档填写的数据和签名
    //这个比较特殊，是固定的，只能是即req.package = Sign=WXPay
    req.package   = @"";
    
    // 随机编码，为了防止重复的，在后台生成
    req.nonceStr  = @"";
    
    // 这个是时间戳，也是在后台生成的，为了验证支付的
    NSString * stamp = @"";
    req.timeStamp = stamp.intValue;
    
    // 这个签名也是后台做的
    req.sign = @"";
    
    //发送请求到微信，等待微信返回onResp
    [WXApi sendReq:req];
}
#pragma mark -- UI
- (void)setUpUI {
    
    //tableView
    [self creatTableView];

}

- (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    self.tableView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.tableView];
}

#pragma mark -- tableView 代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //点击观看
//    //1.首先检测是否登陆
//    if ([Singleton shareSingleton].isLogin) {
//        //登陆了 检测是否支付
//        
//    } else {
//        //去登陆
//    }
    
    
    //2.支付了 开启观看直播
}

#pragma mark -- 区头视图
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
